<?php
require_once 'database/User.php';
require_once 'database/DatabaseConnection.php';
require_once 'command/Command.php';

class GetUserByTagCommand implements Command{

	private $tag;
	private $user;

	public function __construct($tag){
		$this->tag = $tag;
		$this->user = new User();
	}

	public function execute(){
		$string = "<users>";
		DatabaseConnection::connect();
		$arrObject = $this->user->readUserByTag($this->tag);
		$it = $arrObject->getIterator();
		DatabaseConnection::disconnect();
		while($it->valid()){
			$arr = $it->current();
			$string .= "<user>";
			$string .= 	"<id>".$arr['id']."</id>";
			$string .= 	"<name>".$arr['name']."</name>";
			$string .= 	"<password>".$arr['password']."</password>";
			$string .= 	"<listid>".$arr['listid']."</listid>";
			$string .= "</user>";
			break;
		}
		$string .= "</users>";
		return $string;
	}

}